package com.aliyun.heiyu.powermaster.server.dao.impl;


import com.aliyun.heiyu.common.util.JdbcUtil;
import com.aliyun.heiyu.powermaster.server.dao.QosCollectInfoDao;
import com.aliyun.heiyu.powermaster.server.dao.entity.QosCollectInfoEntity;

import java.util.List;

public class QosCollectInfoImpl implements QosCollectInfoDao {
    @Override
    public boolean insert(QosCollectInfoEntity qosCollectInfoEntity) {
        String sql = "INSERT INTO qos_collect_info(business,collect_time,node_name,qos,deployment_mode) " +
            "VALUES (?,?,?,?,?)";
        Object[] params = new Object[5];
        params[0] = qosCollectInfoEntity.getBusiness();
        params[1] = qosCollectInfoEntity.getCollect_time();
        params[2] = qosCollectInfoEntity.getNode_name();
        params[3] = qosCollectInfoEntity.getQos();
        params[4] = qosCollectInfoEntity.getDeployment_mode();
        return JdbcUtil.update(sql, params);

    }

    @Override
    public QosCollectInfoEntity findLatestOne(String business) {
        String sql = "SELECT * FROM qos_collect_info WHERE business = ? AND node_name=1 ORDER BY collect_time DESC LIMIT 0,1 ";
        Object[] params = new Object[1];
        params[0] = business;
        return JdbcUtil.queryForBean(sql, params, QosCollectInfoEntity.class);

    }

    @Override
    public QosCollectInfoEntity findLastestOneByName(String name) {
        String sql = "SELECT * FROM qos_collect_info WHERE node_name = ? ORDER BY collect_time DESC LIMIT 0,1 ";
        Object[] params = new Object[1];
        params[0] = name;
        return JdbcUtil.queryForBean(sql, params, QosCollectInfoEntity.class);
    }

    @Override
    public List<QosCollectInfoEntity> findByCondition(String business, String startTime, String endTime) {
        String sql = "SELECT * FROM qos_collect_info WHERE business = ? AND node_name = 1 AND collect_time BETWEEN ? AND ? ";
        Object[] params = new Object[3];
        params[0] = business;
        params[1] = startTime;
        params[2] = endTime;
        return JdbcUtil.queryForList(sql, params, QosCollectInfoEntity.class);

    }
}
